home *** CD-ROM | disk | FTP | other *** search
- /*
- -- MailUnreadWidget.js
- -- MailUnreadWidget
-
- -- Created by ?? ? on 05/05/25
- -- Copyright (c) 2005 QueueSoft. All rights reserved.
- */
- var version = 'ver 1.3';
- var timerInterval = null;
- var subj_timerInterval = null;
- var subj_waitTimerInterval = null;
- var mailappStatus = false;
- var refreshSecond = 30 * 1000;
- var account_num = 0;
- var mailbox_num = 0;
- var unread_num = 0;
- var unread_idx = 1;
- var subj_animating = false;
-
- var select_account = 0;
- var select_mailbox = 0;
- var subject_animate = 0;
-
- function getLocalizedString (key)
- {
- try {
- return localizedStrings[key];
- } catch (ex) {}
-
- return key;
- }
-
- function onshow () {
- // MailUnreadPlugin.logMessage("js:onshow");
-
- if (timerInterval == null) {
- timerInterval = setInterval("refreshScreen();",refreshSecond);
- }
- subj_animating = false;
- refreshScreen();
- }
-
- function onhide () {
- // MailUnreadPlugin.logMessage("js:onhide");
-
- if (timerInterval != null) {
- // clear the timer
- clearInterval(timerInterval);
- timerInterval = null;
- }
- if (subj_timerInterval != null) {
- // clear the timer
- clearInterval(subj_timerInterval);
- subj_timerInterval = null;
- }
- if (subj_waitTimerInterval != null) {
- // clear the timer
- clearInterval(subj_waitTimerInterval);
- subj_waitTimerInterval = null;
- }
- }
-
- function startRefreshTimer()
- {
- if ( timerInterval != null )
- {
- clearInterval( timerInterval );
- timerInterval = null;
- }
-
- timerInterval = setInterval("refreshScreen();",refreshSecond);
- }
-
- function loaded()
- {
-
- document.getElementById("unread_icon1").style.display = 'none'
- select_account = 1;
- select_mailbox = 0;
- // restore saved account No
- if (window.widget) {
- var save_account = widget.preferenceForKey(createkey("account"));
- if(save_account != null)
- select_account = save_account;
- else
- select_account = 1;
- }
- // restore saved mailbox No
- if (window.widget) {
- var save_mailbox = widget.preferenceForKey(createkey("mailbox"));
- if(save_mailbox != null)
- select_mailbox = save_mailbox;
- else
- select_mailbox = 0;
- }
- // restore saved subject_animate
- if (window.widget) {
- var save_animate = widget.preferenceForKey(createkey("animate"));
- if(save_animate != null)
- subject_animate = save_animate;
- else
- subject_animate = 0;
- }
- MailUnreadPlugin.setAccount(select_account);
- MailUnreadPlugin.setMailbox(select_mailbox);
-
- refreshScreen();
-
- startRefreshTimer();
-
- }
-
- function refreshScreen()
- {
- // MailUnreadPlugin.logMessage("js:refreshScreen");
-
- CheckMailapp();
- if(mailappStatus) {
- if(account_num == 0) {
- account_num = MailUnreadPlugin.getAccountCount();
- mailbox_num = MailUnreadPlugin.getMailboxCount();
- SetSelectAccount();
- SetSelectMailbox();
- }
- document.getElementById("account-popup").style.visibility = 'visible';
- document.getElementById("mailbox-popup").style.visibility = 'visible';
- unread_num = MailUnreadPlugin.getUnreadCount();
- GetSubject();
- } else {
- document.getElementById("unread_icon1").style.display = 'none';
- document.getElementById("accountName").innerHTML = null;
- document.getElementById("mailBoxName").innerHTML = null;
- document.getElementById("subject1").innerHTML = null;
- document.getElementById("account-popup").style.visibility = 'hidden';
- document.getElementById("mailbox-popup").style.visibility = 'hidden';
- }
- }
-
- function CheckMailapp()
- {
- // MailUnreadPlugin.logMessage("js:CheckMailapp");
-
- var run = MailUnreadPlugin.isRunning();
- var result = document.getElementById("mailStatus");
- if(run == 0) {
- result.innerHTML = getLocalizedString('None');
- mailappStatus = false;
- } else {
- result.innerHTML = getLocalizedString('Running');
- mailappStatus = true;
- }
- }
-
- function GetSubject()
- {
- // MailUnreadPlugin.logMessage("js:GetSubject");
-
- if(select_mailbox != 0) {
- document.getElementById("mailBoxTitle").style.left = "230px";
- document.getElementById("mailBoxName").style.left = "320px";
- } else {
- document.getElementById("mailBoxTitle").style.left = "380px";
- document.getElementById("mailBoxName").style.left = "470px";
- }
- document.getElementById("accountName").innerHTML = MailUnreadPlugin.getAccountAtIndex(select_account);
- document.getElementById("mailBoxName").innerHTML = MailUnreadPlugin.getMailboxAtIndex(select_mailbox);
-
- if(unread_num > 0) {
- if(subject_animate == 1) {
- document.getElementById("unread_icon1").style.display = 'block';
- if( !subj_animating ) {
- document.getElementById("subject1").innerHTML = MailUnreadPlugin.getUnreadSubjectAtIndex(unread_idx);
- unreadSubjectShowWait();
- }
- } else {
- if(MailUnreadPlugin.getUnreadAtIndex(1) == 1)
- document.getElementById("unread_icon1").style.display = 'block';
- else
- document.getElementById("unread_icon1").style.display = 'none';
- document.getElementById("subject1").innerHTML = MailUnreadPlugin.getSubjectAtIndex(1);
- }
- } else {
- if (subj_waitTimerInterval != null)
- {
- clearInterval (subj_waitTimerInterval);
- subj_waitTimerInterval = null;
- }
- subj_animating = false;
- document.getElementById ('subject1').style.top = '0px';
- document.getElementById("unread_icon1").style.display = 'none';
- document.getElementById("subject1").innerHTML = MailUnreadPlugin.getSubjectAtIndex(1);
- }
- }
-
- function unreadSubjectShowWait()
- {
- // MailUnreadPlugin.logMessage("js:unreadSubjectShowWait");
- if (subj_waitTimerInterval != null)
- {
- clearInterval (subj_waitTimerInterval);
- subj_waitTimerInterval = null;
- }
- if(unread_num > 0) {
- subj_waitTimerInterval = setInterval("subj_hide();",5000);
- subj_animating = true;
- } else {
- subj_animating = false;
- }
- }
-
- function SetSelectAccount()
- {
- // MailUnreadPlugin.logMessage("js:SetSelectAccount");
- var select = document.getElementById ('account-popup');
- var c = account_num;
-
- for (var i = 1; i <= c; ++i)
- {
-
- var element = document.createElement("option");
- element.innerText = MailUnreadPlugin.getAccountAtIndex(i);
- select.appendChild (element);
- }
-
- }
-
- function SetSelectMailbox()
- {
- // MailUnreadPlugin.logMessage("js:SetSelectMailbox");
- var select = document.getElementById ('mailbox-popup');
- var c = mailbox_num;
-
- for (var i = 0; i <= c; ++i)
- {
-
- var element = document.createElement("option");
- element.innerText = MailUnreadPlugin.getMailboxAtIndex(i);
- select.appendChild (element);
- }
-
- }
-
- function ChangeAccount(accountSelect)
- {
- select_account = accountSelect.selectedIndex + 1;
- MailUnreadPlugin.setAccount(select_account);
- // save select account No
- widget.setPreferenceForKey(select_account, createkey("account"));
- }
-
- function ChangeMailbox(mailboxSelect)
- {
- select_mailbox = mailboxSelect.selectedIndex;
- MailUnreadPlugin.setMailbox(select_mailbox);
- // save select mailbox No
- widget.setPreferenceForKey(select_mailbox, createkey("mailbox"));
- }
-
- function ChangeAnimate(animateCheck)
- {
- var check = animateCheck.checked;
- if(check) {
- widget.setPreferenceForKey(1, createkey("animate"));
- subject_animate = 1;
- } else {
- widget.setPreferenceForKey(0, createkey("animate"));
- subject_animate = 0;
- }
- }
-
- function showbackside(event)
- {
- var front = document.getElementById("front-panel");
- var back = document.getElementById("back-panel");
-
- if (window.widget)
- widget.prepareForTransition("ToBack");
- onhide();
- document.getElementById('version').innerHTML = version;
- front.style.display="none";
- back.style.display="block";
-
- if (window.widget)
- setTimeout ('widget.performTransition();', 0);
-
-
- document.getElementById('fliprollie').style.display = 'none';
- }
-
- function doneClicked() {
- var front = document.getElementById("front-panel");
- var back = document.getElementById("back-panel");
-
- if (window.widget)
- widget.prepareForTransition("ToFront");
-
-
- front.style.display="block";
- back.style.display="none";
-
- setTimeout ('flipitback();', 0);
- onshow();
-
- }
-
-
- function flipitback()
- {
- // updateTime(false);
- if (window.widget)
- setTimeout("widget.performTransition();", 0);
- }
-
- var flipShown = false;
- var subjshown = false;
-
- var animation = {duration:0, starttime:0, to:1.0, now:0.0, from:0.0, element:null, timer:null};
-
- var subj_animation = {duration:0, starttime:0, to:1.0, now:0.0, from:0.0, element:null, timer:null};
-
- // Returns val if min < val < max
- // Returns min if val <= min
- // Returns max if val >= max
-
- function limit_3 (val, min, max)
- {
- return val < min ? min : (val > max ? max : val);
- }
-
- function computeNextFloat (from, to, ease)
- {
- return from + (to - from) * ease;
- }
-
- function subj_animate()
- {
- var T;
- var ease;
- var time = (new Date).getTime();
-
-
- T = limit_3(time-subj_animation.starttime, 0, subj_animation.duration);
-
- if (T >= subj_animation.duration)
- {
- clearInterval (subj_animation.timer);
- subj_animation.timer = null;
- subj_animation.now = subj_animation.to;
- }
- else
- {
- ease = 0.5 - (0.5 * Math.cos(Math.PI * T / subj_animation.duration));
- subj_animation.now = computeNextFloat (subj_animation.from, subj_animation.to, ease);
- }
-
- subj_animation.element.style.top = subj_animation.now + "px";
- }
-
- function subj_hide ()
- {
- // fade in the flip widget
- if (subj_animation.timer != null)
- {
- clearInterval (subj_animation.timer);
- subj_animation.timer = null;
- }
-
- var starttime = (new Date).getTime() - 13; // set it back one frame
-
- subj_animation.duration = 500;
- subj_animation.starttime = starttime;
- subj_animation.element = document.getElementById ('subject1');
- subj_animation.timer = setInterval ("subj_animate();", 13);
- // subj_animation.from = subj_animation.now;
- subj_animation.from = 0.0;
- subj_animation.to = 20.0;
- subj_animate();
-
- if (subj_waitTimerInterval != null)
- {
- clearInterval (subj_waitTimerInterval);
- subj_waitTimerInterval = null;
- }
- subj_waitTimerInterval = setInterval("subj_show();",1000);
-
- }
-
- function getNextSubjectIdx()
- {
- unread_idx++;
- if(unread_idx > unread_num) {
- unread_idx = 1;
- }
- return unread_idx;
- }
-
- function subj_show ()
- {
- idx = getNextSubjectIdx();
- document.getElementById("subject1").innerHTML = MailUnreadPlugin.getUnreadSubjectAtIndex(idx);
-
- // fade in the flip widget
- if (subj_animation.timer != null)
- {
- clearInterval (subj_animation.timer);
- subj_animation.timer = null;
- }
-
- var starttime = (new Date).getTime() - 13; // set it back one frame
-
- subj_animation.duration = 500;
- subj_animation.starttime = starttime;
- subj_animation.element = document.getElementById ('subject1');
- subj_animation.timer = setInterval ("subj_animate();", 13);
- subj_animation.from = -20.0;
- subj_animation.to = 0.0;
- subj_animate();
-
- unreadSubjectShowWait();
- }
-
- function animate()
- {
- var T;
- var ease;
- var time = (new Date).getTime();
-
-
- T = limit_3(time-animation.starttime, 0, animation.duration);
-
- if (T >= animation.duration)
- {
- clearInterval (animation.timer);
- animation.timer = null;
- animation.now = animation.to;
- }
- else
- {
- ease = 0.5 - (0.5 * Math.cos(Math.PI * T / animation.duration));
- animation.now = computeNextFloat (animation.from, animation.to, ease);
- }
-
- animation.element.style.opacity = animation.now;
- }
-
- function mousemove (event)
- {
- if (!flipShown)
- {
- // fade in the flip widget
- if (animation.timer != null)
- {
- clearInterval (animation.timer);
- animation.timer = null;
- }
-
- var starttime = (new Date).getTime() - 13; // set it back one frame
-
- animation.duration = 500;
- animation.starttime = starttime;
- animation.element = document.getElementById ('flip');
- animation.timer = setInterval ("animate();", 13);
- animation.from = animation.now;
- animation.to = 1.0;
- animate();
- flipShown = true;
- }
- }
-
- function mouseexit (event)
- {
- if (flipShown)
- {
- // fade in the flip widget
- if (animation.timer != null)
- {
- clearInterval (animation.timer);
- animation.timer = null;
- }
-
- var starttime = (new Date).getTime() - 13; // set it back one frame
-
- animation.duration = 500;
- animation.starttime = starttime;
- animation.element = document.getElementById ('flip');
- animation.timer = setInterval ("animate();", 13);
- animation.from = animation.now;
- animation.to = 0.0;
- animate();
- flipShown = false;
- }
- }
-
- function onremove ()
- {
- if (window.widget)
- {
- widget.setPreferenceForKey (null, createkey("account"));
- widget.setPreferenceForKey (null, createkey("mailbox"));
- }
- }
-
- if (window.widget)
- {
- widget.onremove = onremove;
- widget.onshow = onshow;
- widget.onhide = onhide;
- }
-
- function enterflip(event)
- {
- document.getElementById('fliprollie').style.display = 'block';
- }
-
- function exitflip(event)
- {
- document.getElementById('fliprollie').style.display = 'none';
- }
-
- function createkey(key)
- {
- return widget.identifier + "-" + key;
- }
-